import 'package:flutter/material.dart';
import 'package:mi_mang_flutter/page/setting/setting_router.dart';
import 'package:mi_mang_flutter/provider/theme_provider.dart';
import 'package:mi_mang_flutter/routers/fluro_navigator.dart';
import 'package:mi_mang_flutter/utils/locale_util.dart';
import 'package:provider/provider.dart';

class SettingFontPage extends StatefulWidget {
  SettingFontPage({Key? key}) : super(key: key);

  @override
  _SettingFontPageState createState() => _SettingFontPageState();
}

class _SettingFontPageState extends State<SettingFontPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(i18n(context).font),
        centerTitle: true,
        actions: <Widget>[
          Semantics(
            button: true,
            label: i18n(context).fontSize,
            child: IconButton(
              tooltip: i18n(context).fontSize,
              icon: Icon(Icons.text_fields),
              onPressed: () {
                NavigatorUtils.push(
                    context, SettingRouter.commonSettingFontSize);
              },
            ),
          ),
        ],
      ),
      body: _buildBody(),
    );
  }

  Widget _buildBody() {
    return ListView.builder(
      shrinkWrap: true,
      itemCount: ThemeProvider.fontValueList.length,
      itemBuilder: (context, index) {
        var model = Provider.of<ThemeProvider>(context);
        return Material(
          child: Column(
            children: <Widget>[
              RadioListTile(
                value: index,
                groupValue: model.fontIndex,
                title: Text(
                  ThemeProvider.fontName(index, context),
                ),
                onChanged: (dynamic index) {
                  model.switchFont(index);
                },
                controlAffinity: ListTileControlAffinity.trailing,
              ),
              index != ThemeProvider.fontValueList.length - 1
                  ? Divider()
                  : SizedBox.shrink(),
            ],
          ),
        );
      },
    );
  }
}
